package com.athena.dal.dao;

import java.util.List;

import javax.persistence.EntityManager;

import org.springframework.beans.factory.annotation.Autowired;

import com.athena.dal.entities.Department;
import com.athena.dal.entities.Faculty;
/**
 * 
 * @author Ajit.Kumar1
 *
 */

public class DepartmentDaoImpl implements DepartmentDao {
	
	@Autowired
	private GenericDao genericDao;
	
	@Override
	public List<Faculty> findByDepartmentId(String departmentId) {
		if(departmentId == null){
			throw new IllegalArgumentException("DepartmentId is null");
		}
		List<Faculty> faculties = null;
		if(genericDao != null){
			EntityManager entityManager = genericDao.getEntityManager();
			if(entityManager != null){
				faculties = (List<Faculty>) entityManager.createNamedQuery("Faculty.findByDepartmentId").setParameter("departmentId", departmentId).getResultList();
			}else {
				System.err.println(getClass().getName() + " :: Entity Manager is NULL");
			}
		}
		return faculties;
	}

	@Override
	public List<Department> getAllDepartments() {
		List<Department> departments = null;
		if(genericDao != null){
			EntityManager entityManager = genericDao.getEntityManager();
			if(entityManager != null){
				departments = (List<Department>) entityManager.createNamedQuery("Department.find").getResultList();
			}else {
				System.err.println(getClass().getName() + " :: Entity Manager is NULL");
			}
		}
		return departments;
	}
	
	

}
